import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', {
  state: () => ({
    count: 0,
    name: 'Counter Store',
    arr: []
  }),

  getters: {
    doubleCount: (state) => state.count * 2
  },

  actions: {
    increment() {
      this.count++

      let id = this.arr.length + 1
      let time = new Date().getTime()
      this.arr.push({id: id, time: time})
      console.log(this.arr)
      
    },
    decrement() {
      if (this.arr.length > 0) {
        this.count--
        this.arr.splice(this.arr.length - 1, 1)
      }
    },
  },

  persist: true
})